home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / Z4Z4BLD.C < prev    next >
C/C++ Source or Header  |  1995-08-08  |  10KB  |  355 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    z4z4bld.c
  5. //   Title:    9-Digit ZIP Code Directory -- on CD-ROM
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains the program entry point for
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <z4.h>
  41.  
  42.  
  43. //----------------------------------------------------------------------------
  44. //    Stack size
  45. //----------------------------------------------------------------------------
  46. #if COMPILER_BORLAND && (OS_DOS || OS_WINDOWS)
  47. unsigned _stklen = 0x4000;
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //    Globals
  53. //----------------------------------------------------------------------------
  54.  
  55. //
  56. // A useless string which is simply embedded in the executable.
  57. //
  58. PSZ __pszCredits__ = "Written by John M Weeder, 1993";
  59.  
  60.  
  61. //
  62. //    This should contain a program description which will be displayed as
  63. //    part of the program's help text.
  64. //
  65. static PCSZ pcszDescription =
  66.     "This program compresses a ZIP+4 data file.";
  67.  
  68. //
  69. //    Program command line options
  70. //
  71. static DATACFG dcfg;
  72. static PZ4_PF_TBL pf_tbl = NULL;
  73.  
  74. static BOOL fCompress = FALSE;
  75. static BOOL fIndex = FALSE;
  76. static BOOL fRecNo = FALSE;
  77. static BOOL fCheck = FALSE;
  78. static BOOL fCrc = FALSE;
  79. static CHAR szConfig[MAX_PATH] = "z4z4";
  80. static BOOL fNoDelete = FALSE;
  81. static BS_CMDOPT acmdopt[] =
  82.     {
  83.     { "CHECK",        (PVOID)&fCheck,        CMDOPT_TRUE,             "Validate CRC codes."},
  84.     { "COMPRESS",    (PVOID)&fCompress,    CMDOPT_TRUE,             "Compress data file."},
  85.     { "CRC",            (PVOID)&fCrc,            CMDOPT_TRUE,         "Generate CRC codes."},
  86.     { "INDEX",        (PVOID)&fIndex,        CMDOPT_TRUE,             "Index data file."},
  87.     { "NODELETE",    (PVOID)&fNoDelete,    CMDOPT_TRUE,            "Don't delete old files."},
  88.     { "RECNO",        (PVOID)&fRecNo,        CMDOPT_TRUE,             "Process record count file."},
  89.     { "config",     (PVOID)szConfig,        CMDOPT_FILESPEC(80), "Configuration file name."},
  90.     BS_CMDOPT_NULL,
  91.     };
  92.  
  93.  
  94. //----------------------------------------------------------------------------
  95. //   Description:    
  96. //    Parameters:
  97. //       Returns:    
  98. //----------------------------------------------------------------------------
  99. VOID FN_E Z4Strip(PDATACFG pcfg, PRECID precid, PSZ _FAR_ *apsz, PBYTE pb)
  100. {
  101. static SIZET cPriNoKey;
  102. static SIZET cPriNameKey;
  103. static SIZET cPriName;
  104. static SIZET cPriNoLo;
  105. static SIZET cPriNoHi;
  106. static SIZET cAddonLo;
  107. static SIZET cAddonHi;
  108. static SIZET cSuffix;
  109. static SIZET cSecName;
  110. static SIZET cRecType;
  111.     CHAR szPriName[MAX_PRI_NAME+1];
  112.     Z4_SUFFIX suffix;
  113.     BOOL fOrdinal;
  114.     CHAR szPriLo[MAX_PRI_NO+1];
  115.     CHAR szPriHi[MAX_PRI_NO+1];
  116.     NOTUSED(pb);
  117.     NOTUSED(precid);
  118.  
  119.     if (apsz == NULL)
  120.         {
  121.         cPriNoKey   = DataField(pcfg, "pri_no_key");
  122.         cPriNameKey = DataField(pcfg, "pri_name_key");
  123.         cPriName        = DataField(pcfg, "pri_name");
  124.         cPriNoLo        = DataField(pcfg, "pri_no_lo");
  125.         cPriNoHi        = DataField(pcfg, "pri_no_hi");
  126.         cAddonLo        = DataField(pcfg, "addon_lo");
  127.         cAddonHi        = DataField(pcfg, "addon_hi");
  128.         cSuffix        = DataField(pcfg, "suffix");
  129.         cSecName        = DataField(pcfg, "sec_name");
  130.         cRecType        = DataField(pcfg, "record_type_code");
  131.         return ;
  132.         }
  133.     Z4Clean(apsz[cPriName]);
  134.     Z4Clean(apsz[cSuffix]);
  135.     Z4Clean(apsz[cSecName]);
  136.     Z4Z4CompressRange(apsz[cPriNoHi]);
  137.     Z4Z4CompressRange(apsz[cPriNoLo]);
  138.  
  139.     strcpy(szPriLo, apsz[cPriNoLo]);
  140.     strcpy(szPriHi, apsz[cPriNoHi]);
  141.     if (szPriLo[0] == '-')
  142.         szPriLo[0] = '0';
  143.     if (szPriHi[0] == '-')
  144.         szPriHi[0] = '0';
  145.  
  146.     //
  147.     //    Standardize the RR default records
  148.     //
  149. //    if (apsz[cRecType][0] == '1' && apsz[cRecType][1] == '8')
  150.     if (apsz[cRecType][0] == 'R') // new code replaces old code above
  151.         {
  152.         if (memcmp(apsz[cPriNoHi], "0000000000", 10) == 0
  153.         && memcmp(apsz[cPriNoLo], "0000000000", 10) == 0)
  154.             {
  155.             memset(apsz[cPriNoHi], ' ', 10);
  156.             memset(apsz[cPriNoLo], ' ', 10);
  157.             szPriLo[0] = '\0';
  158.             szPriHi[0] = '\0';
  159.             }
  160.         }
  161.     //
  162.     //    Handle odd-ball addon's for non-deliverables
  163.     //
  164.  
  165.     if ((apsz[cAddonLo][1] == 'N' && apsz[cAddonLo][2] == 'D')
  166.       || (apsz[cAddonLo][2] == 'N' && apsz[cAddonLo][3] == 'D'))
  167.     apsz[cAddonLo][0] = '\0';
  168.  
  169.     if ((apsz[cAddonHi][1] == 'N' && apsz[cAddonHi][2] == 'D')
  170.     || (apsz[cAddonHi][2] == 'N' && apsz[cAddonHi][3] == 'D'))
  171.     apsz[cAddonHi][0] = '\0';
  172.  
  173.     //
  174.     //    Do some parsing on the primary name so that the sort key may
  175.     //    be built. Remove any trailing suffix words and any ordinal suffixes.
  176.     //
  177.  
  178.     Z4Z4CompressPriName(apsz[cPriName], szPriName, &suffix, &fOrdinal);
  179.  
  180.     //
  181.     //    Build the phonetics!
  182.     //
  183.  
  184.     if (szPriHi[0] && !szPriLo[0]) {
  185.         strcpy(szPriLo, szPriHi);
  186.     }
  187.     Metaphone(szPriName, (PBYTE)apsz[cPriNameKey], 3);
  188.     AlNumKey(Z4Z4CompressRange(szPriLo), (PBYTE)apsz[cPriNoKey], 3);
  189.     return;
  190. }
  191.  
  192.  
  193. //----------------------------------------------------------------------------
  194. //   Description:   //added description...builds the z4z4.inp,dld, and dlx files
  195. //    Parameters:
  196. //       Returns:
  197. //----------------------------------------------------------------------------
  198. BOOL FN_E Compress(void)
  199. {
  200.     LONG l;
  201.     CHAR szWork[MAX_PATH];
  202.     CHAR szFinance[MAX_PATH];
  203.  
  204.     if (!Z4PofCreate(&pf_tbl, Z4_PF_TBL_WORK_MAX)
  205.     || !Z4PofRead(pf_tbl, Z4_PF_TBL_WORK))
  206.     return FALSE;
  207.  
  208.     if (pf_tbl->lSize == 0)
  209.     {
  210.         Output("No POF's to process.\n");
  211.         return TRUE;
  212.         }
  213.     strcpy(szWork, "z4z4.inp");
  214.     if (!FnameQualify(szWork, "inp", EnvGet("DATA"), 0))
  215.     return FALSE;
  216.  
  217.     if (FnameIsFile(szWork))
  218.     if (!FnameDelete(szWork))
  219.         return FALSE;
  220.  
  221. #if OS_DOS
  222.     Output("\nPress escape to abort...\n\n");
  223. #endif
  224.  
  225.     Output("Combining finance records:\n");
  226.     for (l = 0; l < pf_tbl->lSize; ++l)
  227.     {
  228. #if OS_DOS
  229.     while (KbdReady())
  230.        if (KbdChar() == '\x1B')
  231.         {
  232.         Output("\nAborted!\n");
  233.         return FALSE;
  234.         }
  235. #endif
  236.     strb2a(pf_tbl->abPof[(SIZET)l], MAX_FINANCE_BCD, szFinance, MAX_FINANCE, TRUE);
  237.     szFinance[MAX_FINANCE] = '\0';
  238.     Output("   %s\n", szFinance);
  239.  
  240.     if (!FnameQualify(szFinance, "inp", EnvGet("DATA"), 0))
  241.             return FALSE;
  242.  
  243.         if (!CopyFile(szFinance, szWork, FCOPY_APPEND|FCOPY_NO_DATE, NULL))
  244.             return FALSE;
  245.  
  246.         if (!fNoDelete)
  247.             if (!FnameDelete(szFinance))
  248.                 return FALSE;
  249.         }
  250.  
  251.         if (!DataConfigFiles(&dcfg, szWork))
  252.         return FALSE;
  253.     if (!DataStrip(&dcfg, Z4Strip))
  254.        {
  255.        Output("Failed stripping fixed length records.\n");
  256.        return FALSE;
  257.        }
  258.     if (!fNoDelete)
  259.         {
  260.         if (FnameIsFile(dcfg.szInput))
  261.             if (!FnameDelete(dcfg.szInput))
  262.                 return FALSE;
  263.         }
  264.  
  265.     if (!DataSort(&dcfg))
  266.        {
  267.         Output("Failed sorting delimited data file.\n");
  268.        return FALSE;
  269.        }
  270.     if (!DataCompress(&dcfg, Z4Z4Compress, DAC_XREF|DAC_RECNO))
  271.        {
  272.        Output("Failed compressing data file.\n");
  273.        return FALSE;
  274.        }
  275.     if (!fNoDelete)
  276.        if (!DataDelimitDelete(&dcfg))
  277.           {
  278.           Output("Failed deleting temporary data files.\n");
  279.           return FALSE;
  280.           }
  281.  
  282.     Z4PofDelete(pf_tbl, l);                    // Update work table!
  283.     if (!Z4PofWrite(pf_tbl, Z4_PF_TBL_WORK))
  284.     return FALSE;
  285.  
  286.     return TRUE;
  287. }
  288.  
  289.  
  290. //----------------------------------------------------------------------------
  291. //   Description:    main() - Program entry point
  292. //    Parameters:    Standard C parameters
  293. //       Returns:    DOS return code.
  294. //----------------------------------------------------------------------------
  295. int main(int argc, char **argv)
  296. {
  297. static BS_CFG cfg = CFG_DFT;
  298.     int retval = 99;
  299.  
  300.     //
  301.     //    Initialize base library
  302.     //
  303.     BaseLibraryInitialize(argc, argv, &cfg);
  304.     BaseTitle("$Revision:  93.1  $", __DATE__, __TIME__, "9-Digit ZIP Disc ZIP+4 File Build");
  305.     if (!BaseTitleHelp(acmdopt, pcszDescription,NULL))
  306.         return 99;
  307.  
  308.     DioSetDataPath(getenv("DATA"));
  309.     if (!DataConfigRead(szConfig, &dcfg))
  310.         {
  311.         Output("Failed reading configuration file.\n");
  312.         goto ERROR_EXIT;
  313.         }
  314.     if (fCompress)
  315.         {
  316.         if (!Compress())
  317.             {
  318.            Output("Failed compressing delimited data file.\n");
  319.            goto ERROR_EXIT;
  320.             }
  321.         }
  322.     if (fCrc)
  323.         if (!DioCrc(dcfg.szData, dcfg.szLogical, DFT_ISAM_DATA, NULL))
  324.            {
  325.            Output("Failed generating CRC codes for data area.\n");
  326.            return 99;
  327.            }
  328.     if (fRecNo)
  329.         if (!DataRecNo(&dcfg))
  330.            {
  331.            Output("Failed generating record number index.\n");
  332.            return 99;
  333.            }
  334.     if (fIndex)
  335.         if (!DataIndex(&dcfg, Z4Z4Index))
  336.            {
  337.            Output("Failed indexing data file.\n");
  338.            return 99;
  339.            }
  340.     if (fCheck)
  341.         if (!DioCheck(dcfg.szData))
  342.            {
  343.            Output("Failed verifying data file.\n");
  344.            return 99;
  345.            }
  346.     retval = 0;
  347. ERROR_EXIT:
  348.     Z4PofDestroy(pf_tbl);
  349.     DioCloseAll();
  350.     return retval;
  351. }
  352. //----------------------------------------------------------------------------
  353. //------------------------------- End of File --------------------------------
  354. //----------------------------------------------------------------------------
  355.